﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Resources;
using System.IO;
using System.Drawing.Imaging;

namespace Screenshot2Disk
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            if (SecurityHelper.IsAdmin())
                this.Text += " (Admin)";
        }

        private void SetGui()
        {
            var isInstalled = RegistryHelper.IsRegistered();

            registerButton.Enabled = !isInstalled;
            unregisterButton.Enabled = isInstalled;

            this.outputFormatBox.SelectedIndex = MySettings.Default.OutputFormat;
        }

        private void checkRegistryButton_Click(object sender, EventArgs e)
        {
            this.SetGui();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.SetGui();
        }

        private void unregisterButton_Click(object sender, EventArgs e)
        {
            RegistryHelper.UnregisterShellExt();
            SetGui();
        }

        private void registerButton_Click(object sender, EventArgs e)
        {
            RegistryHelper.RegisterShellExt();
            SetGui();
        }

        private void restartElevatedButton_Click(object sender, EventArgs e)
        {
            SecurityHelper.StartElevated(this);
        }

        private void outputFormatBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            MySettings.Default.OutputFormat = outputFormatBox.SelectedIndex;
            MySettings.Default.Save();
        }

        public static void GetImageSettings(out ImageFormat outputformat, out int compression)
        {
            switch (MySettings.Default.OutputFormat)
            {
                case 0:
                    outputformat = ImageFormat.Png;
                    compression = 100;
                    return;
                case 1:
                    outputformat = ImageFormat.Jpeg;
                    compression = 75;
                    return;
                case 2:
                    outputformat = ImageFormat.Jpeg;
                    compression = 50;
                    return;
                case 3:
                    outputformat = ImageFormat.Jpeg;
                    compression = 30;
                    return;
            }

            throw new Exception();
        }
    }
}
